﻿<div class="k-block divToolbar" style="margin: 5px">
    <div style="display: inline-block;">
        <select id="selArchive" style="width: 400px"></select>
    </div>
    <div style="display: inline-block;">
        <select id="selBureau"></select>
    </div>
</div>

<div id="tbs_B4SampleBureau" style="margin: 5px">
    <ul>
        <li class="k-state-active">各机构进度</li>
        <li>学校情况</li>
    </ul>
    <div>
        <div id="chart_bar"></div>
    </div>
    <div>
        <div class="k-block divToolbar" style="margin: 5px">
            <div style="display: inline-block;">
                <select id="selFinished">
                    <option value="">全部</option>
                    <option value="true">已完成</option>
                    <option value="false" selected="selected">未完成</option>
                </select>
            </div>
            <span class="k-textbox k-space-right">
                <input type="text" placeholder="请输入学校名称或编码" id="txtKey" />
                <a href="javascript:GridFilter()" class="k-icon k-i-search">&nbsp;</a>
            </span>
        </div>
        <div id="grid_B4Sample" style="text-align: center;"></div>
    </div>
</div>

<script class="init">
    var his = "@(ViewBag.History)" == "True";
    if (his)
        LocatedMenu("历年报告", "采集报告");
    else
        LocatedMenu("数据分析", "进度统计");

    $("#tbs_B4SampleBureau").kendoTabStrip();

    $("#selArchive").kendoDropDownList({
        dataTextField: "Title",
        dataValueField: "Guid",
        dataSource: Whale.dataSource({
            url: "/Achievements/Archive/Gets",
            getParameters: function () {
                return {
                    aType: 2,
                    expired: his
                }
            }
        }),
        dataBound: function (e) {
            if (this.dataSource.data().length == 0) {
                this.setDataSource(new kendo.data.DataSource({
                    data: [{ Title: "暂无档案", Guid: "" }]
                }));
            }
        },
        change: function (e) {
            BarFilter();
        }
    });
    $("#selBureau").kendoDropDownList({
        dataTextField: "EduName",
        dataValueField: "Guid",
        dataSource: Whale.dataSource({
            url: "/Systems/Bureau/Gets",
            getParameters: function () {
                return { withme: true }
            }
        }),
        change: function (e) {
            BarFilter();
        }
    });

    $("#selFinished").kendoDropDownList({
        change: function (e) {
            GridFilter();
        }
    });

    function BarFilter() {
        $("#chart_bar").data("kendoChart").dataSource.read();
        GridFilter();
    }

    function GridFilter() {
        $("#grid_B4Sample").data("kendoGrid").dataSource.page(0);
    }
</script>

<script class="grid">
    $("#grid_B4Sample").kendoGrid({
        columns: [{
            title: "编码",
            field: "SchoolCode",
            width: 80
        }, {
            title: "学校名称",
            field: "SchoolName",
            attributes: { style: "text-align:left" },
            width: 300
        }, {
            title: "人数",
            field: "Total",
            width: 70
        }, {
            title: "应测",
            field: "Due",
            width: 70
        }, {
            title: "已测",
            field: "Sample",
            width: 70
        }, {
            title: "未测",
            field: "Balance",
            width: 70
        }, {}],
        dataSource: Whale.dataSource({
            url: "/Analyses/ANB/GetB4SampleSchool",
            getParameters: function () {
                var parameters = {
                    aGuid: $("#selArchive").data("kendoDropDownList").value(),
                    bGuid: $("#selBureau").data("kendoDropDownList").value(),
                    key: $.trim($("#txtKey").val()),
                    history:his
                };
                if ($("#selFinished").data("kendoDropDownList").value() != "") {
                    parameters = $.extend(parameters, { finish: $("#selFinished").data("kendoDropDownList").value() });
                }
                return parameters;
            },
            pageSize: 15
        }),
        pageable: {
            messages: {
                empty: "暂无数据"
            }
        },
        dataBound: function (e) {
            //让表头居中
            $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
        }
    });
</script>

<script class="bars">
    $("#chart_bar").kendoChart({
        dataSource: Whale.dataSource({
            url: "/Analyses/ANB/GetB4SampleBureau",
            getParameters: function () {
                return {
                    aGuid: $("#selArchive").data("kendoDropDownList").value(),
                    bGuid: $("#selBureau").data("kendoDropDownList").value(),
                    history:his
                }
            }
        }),
        legend: {
            position: "top"
        },
        seriesDefaults: {
            type: "column",
            stack: {
                type: "100%"
            }
        },
        series: [{
            name: "已完成",
            field: "Finished",
            color: "#f3ac32"
        }, {
            name: "未完成",
            field: "UnFinished",
            color: "#b8b8b8"
        }],
        categoryAxis: {
            field: "EduName",
            labels: {
                //rotation: -45
            },
            majorGridLines: {
                visible: false
            }
        },
        tooltip: {
            visible: true,
            template: "#= series.name #: #= value #"
        }
    });
</script>
